package com.example.petproject.controller;

import com.example.petproject.entity.dto.ProductSearchDTO;
import com.example.petproject.entity.vo.DetailVO;
import com.example.petproject.entity.vo.PageResult;
import com.example.petproject.entity.vo.ProductSearchVO;
import com.example.petproject.entity.vo.ReturnVO;
import com.example.petproject.service.PmsProductService;
import com.example.petproject.service.third.ali.AliYunOSSService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 包名称：com.example.petproject.controller
 * 类名称：PmsProductController
 * 类描述：商品控制器
 * 创建人：@author DrinkMore-HotWater
 * 创建时间：2024年01月12日 15:56
 **/
@RestController
@RequestMapping("pms/product")
@Tag(name = "商品查询接口")
public class PmsProductController {
    @Resource
    private PmsProductService pmsProductService;

    @PostMapping("/search")
    public ReturnVO<PageResult<ProductSearchVO>> getSearch(@RequestBody ProductSearchDTO productSearchDTO){
        PageResult<ProductSearchVO> search = pmsProductService.getSearch(productSearchDTO);
        search.setPageNo(productSearchDTO.getPageNo());
        if (productSearchDTO.getPageSize()!=null){
            search.setPageSize(productSearchDTO.getPageSize());
        }
        search.setTotal(productSearchDTO.getTotal());
        search.setPages(productSearchDTO.getPageS());
        return ReturnVO.ok(search);
    }

    @GetMapping("/detail")
    public ReturnVO<DetailVO> getDetail(Integer spuId){
        return ReturnVO.ok(pmsProductService.getDetail(spuId));
    }

}
